home *** CD-ROM | disk | FTP | other *** search
/ Young & Modern Digital Makeover Magic / Young & Modern Digital Makeover Magic.iso / data1.cab / Media / button3.js < prev    next >
Encoding:
JavaScript  |  1999-10-18  |  2.2 KB  |  70 lines

  1. /*
  2.     The Button3 class
  3.     A three-state button toggled by image events
  4.  
  5.     Notes:
  6.         This script was designed to make it easier to put mouseover
  7.     buttons onto web pages. The button has three defined states:
  8.         Normal- It's appearance when it's just sitting there.
  9.         Hilite- Usually some brighter version of the normal graphic
  10.                 called on a mouseover event.
  11.         Active- A graphic showing the button is turned 'on', like 
  12.                 a play button of a tape recorder.
  13.  
  14.         This constructor assumes the three buttons are .jpg files, 
  15.     whose names follow the convention:
  16.                     baseFilename_N.jpg
  17.                     baseFilename_H.jpg
  18.                     baseFilename_A.jpg
  19.     where N, H, and A are the normal, hilite, and active graphics for the
  20.     button in question. 
  21.  
  22.     For potential future use, I've added a variable that stores the button's
  23.     current state. This could make it easier to add more sophisticated behavior
  24.     to the button for different events (ex: hilite the button on mouseover only
  25.     if it's in its normal state)
  26.  
  27.     Mod history:
  28.         Added an InitState Method, to allow you to initialize the
  29.             button's internal state without changing the graphic.
  30.         Added a filename extenstion to the constructor, allowing you
  31.             to use both .gif and .jpg files.
  32. */
  33. function Button3(imgTagName, baseFilename, extension)
  34. {
  35.     this.theTagName    = imgTagName;
  36.     this.currentState = 0;    
  37.  
  38.     //Use local image caching for speed
  39.     this.normalImg    = new Image();
  40.     this.hiliteImg    = new Image();
  41.     this.activeImg    = new Image();
  42.  
  43.     this.normalImg.src = baseFilename + "_N" + extension;
  44.     this.hiliteImg.src = baseFilename + "_H" + extension;
  45.     this.activeImg.src = baseFilename + "_A" + extension;
  46. }
  47. /*
  48.     Methods used by the Button class.
  49. */
  50. Button3.prototype.SelectNormal = function()
  51. {
  52.     document[this.theTagName].src = this.normalImg.src;
  53.     this.currentState = 0;    
  54. }
  55. Button3.prototype.SelectHilite = function()
  56. {
  57.     document[this.theTagName].src = this.hiliteImg.src;
  58.     this.currentState = 1;    
  59. }
  60. Button3.prototype.SelectActive = function()
  61. {
  62.     document[this.theTagName].src = this.activeImg.src;
  63.     this.currentState = 2;    
  64. }
  65. Button3.prototype.InitialState = function( initState )
  66. {
  67.     if( initState==0 || initState==1 || initState==2 )
  68.         this.currentState = initState;    
  69. }
  70.